/*
 * @Author: your name
 * @Date: 2021-06-01 15:03:22
 * @LastEditTime: 2021-06-01 15:51:11
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \bazai_island_api\app\api\user.js
 */

const Router = require('koa-router')
const router = new Router()

const { RegisterValidator } = require('../../validators/validators')
const { User } = require('../../models/user')
const { ParameterException } = require('../../../core/http-exception')
const { success } = require('../../lib/helper')

router.prefix('/v1/user')

// 注册 新增数据

router.post('/register', async (ctx) => {
  // 思维路径
  // 接收参数
  const v = await new RegisterValidator().validate(ctx)
  const user = {
    email: v.get('body.email'),
    password: v.get('body.password2'),
    nickname: v.get('body.nickname')
  }
  await User.create(user)
  success()
})

module.exports = router
